﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Maticsoft.Web.DishInfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int DId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(DId);
				}
			}
		}
			
	private void ShowInfo(int DId)
	{
		Maticsoft.BLL.DishInfo bll=new Maticsoft.BLL.DishInfo();
		Maticsoft.Model.DishInfo model=bll.GetModel(DId);
		this.lblDId.Text=model.DId.ToString();
		this.txtDTitle.Text=model.DTitle;
		this.txtDTypeId.Text=model.DTypeId.ToString();
		this.txtDPrice.Text=model.DPrice.ToString();
		this.txtDChar.Text=model.DChar;
		this.chkDIsDelete.Checked=model.DIsDelete;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtDTitle.Text.Trim().Length==0)
			{
				strErr+="DTitle不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtDTypeId.Text))
			{
				strErr+="DTypeId格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtDPrice.Text))
			{
				strErr+="DPrice格式错误！\\n";	
			}
			if(this.txtDChar.Text.Trim().Length==0)
			{
				strErr+="DChar不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int DId=int.Parse(this.lblDId.Text);
			string DTitle=this.txtDTitle.Text;
			int DTypeId=int.Parse(this.txtDTypeId.Text);
			decimal DPrice=decimal.Parse(this.txtDPrice.Text);
			string DChar=this.txtDChar.Text;
			bool DIsDelete=this.chkDIsDelete.Checked;


			Maticsoft.Model.DishInfo model=new Maticsoft.Model.DishInfo();
			model.DId=DId;
			model.DTitle=DTitle;
			model.DTypeId=DTypeId;
			model.DPrice=DPrice;
			model.DChar=DChar;
			model.DIsDelete=DIsDelete;

			Maticsoft.BLL.DishInfo bll=new Maticsoft.BLL.DishInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
